﻿using System.Collections.Generic;

namespace CRM.Database.Model
{
  public  class AllConditionsCollection
    {

      public List<AllCondition> AllConditionsList
      {
          get 
          {
              
              var colTransport = new TransportConditionsCollection();
              var colCredit = new CreditConditionsCollection();
              var colPrice= new PriceConditionsCollection();
              var colBonus = new BonusesCollection();

              var result = new List<AllCondition>();

            result.AddRange(GetAllConditionsFromBonusConditionsList(colBonus.BonusesList));
            result.AddRange(GetAllConditionsFromPriceConditionsList(colPrice.PriceConditionsList));
            result.AddRange(GetAllConditionsFromCreditConditionsList(colCredit.CreditConditionsList));
            result.AddRange(GetAllConditionsFromTransportConditionsList(colTransport.TransportConditionsList));

              return result;
          }
      } 


      public  List<AllCondition> GetAllConditionsFromTransportConditionsList(List<TransportConditions> list )
      {
          var result = new List<AllCondition>();
          int id = 0;

          foreach (TransportConditions transport in list)
          {
              var str = "Транспортное условие: "+transport.LegalEntityName+", " + transport.TransportConditionStr + " при загрузке в " +
                        transport.TrucksCapacities.Capacity + " паллетт";

              result.Add(new AllCondition { ConditionText = str, Id = id });
              id++;

          }

          return result;
      }


      public List<AllCondition> GetAllConditionsFromCreditConditionsList(List<CreditConditions> list)
      {
          var result = new List<AllCondition>();
          int id = 0;

          foreach (var credit in list)
          {
              var str = "Кредитное условие: " + credit.CreditConditionStr;
              result.Add(new AllCondition { ConditionText = str, Id = id });
              id++;
          }

          return result;
      }


      public List<AllCondition> GetAllConditionsFromPriceConditionsList(List<PriceConditions> list)
      {
          var result = new List<AllCondition>();
          int id = 0;

          foreach (var price in list)
          {
              var str = "Ценовое условие: " + price.PriceConditionStr;
              result.Add(new AllCondition { ConditionText = str, Id = id });
              id++;
          }

          return result;
      }

      public List<AllCondition> GetAllConditionsFromBonusConditionsList(List<Bonuses> list)
      {
          var result = new List<AllCondition>();
          int id = 0;

          foreach (var bonus in list)
          {
              var str = "Бонусы: " + bonus.BonusStr;
              result.Add(new AllCondition { ConditionText = str, Id = id });
              id++;
          }

          return result;
      }




      public List<AllCondition> GetAllConditionsByCustomer(Customers customer)
      {
          var result = new List<AllCondition>();
          int id = 0;

         
              result.AddRange(GetAllConditionsFromTransportConditionsList(customer.TransportConditions));
         

         result.AddRange(GetAllConditionsFromCreditConditionsList(customer.CreditConditions));

         result.AddRange(GetAllConditionsFromPriceConditionsList(customer.PriceConditions));

         result.AddRange(GetAllConditionsFromBonusConditionsList(customer.Bonuses));

          return result;
      } 

    }
}
